/**
 	DatesField component
 */
package nrb.components
{
	import flash.events.FocusEvent;
	import flash.events.KeyboardEvent;
	import nrb.validations.Validation;
	import mx.controls.DateField;

	/**
	 	Type: Class
	 	@Params:none
	 	@return:none
	 	Desc: Class for date that extends DateField Class
	 */
	public class DatesField extends DateField {
		
		/**
		 	Type: Controller
		 	@Params:none
		 	@return:none
		 	Desc: initializes super class and adds listener on focus out event
		 */
		public function DatesField(){
			super();
			addEventListener(FocusEvent.FOCUS_OUT,validate_field,false);
		}
		
		
		/**
		 	string variable for language property for handling errors
		 */
		private var _lang:String = "";
		/**
		 	Type: Public Function
		 	@Params:value['ENGLISH', 'JAPANESE'] AS String
		 	@return:void
		 	Desc: setter for language property
		 */
		public function set language(value:String): void {
			_lang = value;
		}
		/**
		 	Type: Public Function
		 	@Params:void
		 	@return:String
		 	Desc: getter for language property
		 */
		public function get language(): String {
			return _lang;
		}
		
		
		/**
		 	boolean variable for required property
		 */
		private var _required:Boolean = false;
		/**
		 	Type: Public Function
		 	@Params:value[TRUE | FALSE] AS Boolean
		 	@return:void
		 	Desc: setter for required property
		 */
		public function set required(value:Boolean): void {
			_required = value;
		}
		/**
		 	Type: Public Function
		 	@Params:none
		 	@return:boolean
		 	Desc: getter for required property
		 */
		public function get required(): Boolean {
			return _required;
		}
		
		
		/**
		 * boolean variable for hasError property
		 */
		private var _hasError:Boolean = false;
		/**
		 	Type: Public Function
		 	@Params:value[TRUE | FALSE] AS Boolean
		 	@return:none
		 	Desc: setter for hasError property
		 */
		public function set hasError(value:Boolean): void {
			_hasError = value;
		}
		/**
		 	Type: Public Function
		 	@Params:none
		 	@return:boolean
		 	Desc: getter for hasError property
		 */
		public function get hasError(): Boolean {
			return _hasError;
		}
		
		
		/**
		 	Type: Public Function
		 	@Params:event[KeyboardEvent] AS flash.events.KeyboardEvent
		 	@return:void
		 	Desc: re set the class _text variable from super.text
		 */
		private function set_text(event:flash.events.KeyboardEvent): void {
			//_text = super.text;
		}
		
		/**
		 	Type: Public Function
		 	@Params:event[FocusEvent] AS FocusEvent
		 	@return:void
		 	Desc: validates the field if Required
		 */
		private function validate_field(event:FocusEvent): void {
			var validate:Validation = new Validation();
			var obj:Object;
			if(_required){
				validate.set_validation_type('BLANK');
				obj = validate.validate(super.text, _lang);
			}
			
			if(obj != null){
				if(obj['is_error']){
					super.errorString = obj['error_string'];
					_hasError = obj['is_error'];
				}else{
					super.errorString = '';
					_hasError = obj['is_error'];
				}
			}
		}
		
		/**
		 	Type: Protected Function
		 	@Params:unscaledWidth[1|2|3] AS Number, unscaledHeight[1|2|3] AS Number
		 	@return:void
		 	Desc: overrides the function in super class and Modifies the display if _text var changes
		 */
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			super.updateDisplayList( unscaledWidth, unscaledHeight );
		}
		
	}
}